package com.tanhua.dubbo.test;
import com.tanhua.domain.db.SoultestOption;
import com.tanhua.domain.mongo.Voice;
import com.tanhua.dubbo.DubboServiceApplication;
import com.tanhua.dubbo.mapper.SoultestOptionMapper;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@SpringBootTest(classes = DubboServiceApplication.class)
@RunWith(SpringRunner.class)
public class MongoAutoInsert {

    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private SoultestOptionMapper soultestOptionMapper;

    @Test
    public void test_01() throws ParseException {
       //循环插入50条数据 都为异性

        for (int i = 0; i < 50; i++) {
            Voice voice = new Voice();
            voice.setUserId(Long.parseLong(RandomUtils.nextLong(1,5)+""));
            voice.setGender("woman");
//            voice.setCreated(new Date().getTime());
            long time = new SimpleDateFormat("yyyy-MM-dd").parse("2021-08-15").getTime();
            voice.setCreated(time);
//          voice.setVoiceUrl(time+"");
            voice.setVoiceUrl("https://mytanhua115.oss-cn-shenzhen.aliyuncs.com/images/2021/08/23/bafea528-745e-4837-8a2e-c6b238e11dbf.m4a");
            mongoTemplate.save(voice);
        }
    }

    @Test
    public void test_02() {
        SoultestOption soultestOption = soultestOptionMapper.selectById(1);
        System.out.println(soultestOption);
    }


}
